<%--
  Created by IntelliJ IDEA.
  User: zhukang
  Date: 2021-06-06
  Time: 09:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
    <title>电子文档管理主页</title>
</head>
<body>
<h1 style="text-align: center;">欢迎使用电子文档管理系统</h1>
<p style="text-align: center;">
    <span>文档分类：</span>
    <select id="cid" name="cid">
        <c:forEach items="${edocCategories}" var="edocCategory">
            <option value="${edocCategory.id}">
                ${edocCategory.name}
            </option>
        </c:forEach>
    </select>&nbsp;&nbsp;
    <input type="button" id="sel"   value="查询">&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" id="add" value="新增电子文档">&nbsp;&nbsp;
</p>
<table border="1px" align="center" width="100%" cellspacing="0">
    <thead>
    <tr>
        <th colspan="7" height="80px" style="background-color: cyan;">
            <span style="font-size: 40px;">电子文档列表</span>
        </th>
    </tr>
    <tr style="background-color: darkgray; height: 40px;">
        <th>文档编号</th>
        <th>文档类别</th>
        <th>文档名称</th>
        <th>文档摘要</th>
        <th>文档作者</th>
        <th>上传时间</th>
        <th>文档操作</th>
    </tr>
    </thead>
    <tbody>
        <c:forEach items="${edocEntries}" var="edocEntry">
            <tr align="center">
                <td>${edocEntry.id}</td>
                <td>${edocEntry.cid}</td>
                <td>${edocEntry.title}</td>
                <td>${edocEntry.summary}</td>
                <td>${edocEntry.uploadUser}</td>
                <td><fmt:formatDate value="${edocEntry.createDate}" pattern="yyyy-MM-dd"/></td>
                <td>
                    <a href="edocInfo/${edocEntry.id}">修改</a>
                    <a href="edocInfo/${edocEntry.id}" class="del">删除</a>
                </td>
            </tr>
        </c:forEach>
    </tbody>
    <tfoot></tfoot>
</table>
<form action="#" method="post">
    <input type="hidden" name="_method" value="delete"/>
</form>
</body>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
<script>
    $(function () {
        // 调试jQuery是否正常
        // alert(123);
        // 绑定删除操作
        $(".del").click(function () {
            // 提示
            if (!confirm("确定要删除吗？")){
                // 去除超链接的默认跳转事件
                return false;
            }

            // 提交form表单
            $("form").attr("action", $(this).attr("href")).submit();

            // 取消表单的默认提交事件
            return false;
        })

        $("#add").click(function () {
            location.href = "toAddEdocEntry";
        })

        $("#sel").click(function () {
            var cid = $("#cid").val()
            location.href = "/seledocInfo/" + cid;
        })
    })
</script>
</html>
